﻿using UnityEngine;
using ProtoBuf;
using System.Collections;

public class SampleCode : MonoBehaviour {
	
	public struct item
	{
		[ProtoMember(1)]
		public string id;
		[ProtoMember(2)]
		public string name;
		[ProtoMember(3)]
		public int quality;
	}

	public struct Inventory
	{
		[ProtoMember(1)]
		public item[] items;
	}

	[HideInInspector]
	public string serialiseDIR = System.IO.Directory.GetCurrentDirectory();

	void Awake(){
		SerializeUtility.Init (typeof(Inventory));
		}

	// Use this for initialization
	void Start () {
		//call this once throughout the game
		//SerializeUtility.Init( typeof(Inventory) );
		
		//sample inventory
		Inventory myInventory = new Inventory();
		//sample items. with 1 item on invetory
		item newItem = new item();
		newItem.id = "itemId";
		myInventory.items = new item[]{newItem};
		
		//save the whole inventory by using serializeUtility class
		//SerializeUtility.SaveObject(serialiseDIR,  myInventory);
		SerializeUtility.SaveObject("C:/Users/fie_square/Downloads",  myInventory);
		
		//load and read the object from file
		Inventory loadedInventory = new Inventory ();
		loadedInventory = (Inventory)SerializeUtility.LoadObject("C:/Users/fie_square/Downloads", typeof(Inventory));
		//display the first item
		Debug.Log( loadedInventory.items[0].id );
	}
	
	// Update is called once per frame
	void Update () {
			
	}
}
